import java.util.Arrays;
import java.util.Scanner;

//题目：有一个已经排好序的数组。现输入一个数，要求按原来的规律将它插入数组中。
public class Test30 {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        System.out.println("请输入一个数:");
        int num = console.nextInt();
        insert(num);

    }

    public static void insert(int num) {
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 100);
        }
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
        int t = 0;
        for (int i = 0; i < arr.length; i++) {
            if (num > arr[i]) {
                t = i;
            } else {
                break;
            }
        }
        int[] brr = new int[arr.length + 1];
        System.arraycopy(arr, 0, brr, 0, t + 1);
        System.arraycopy(arr, t + 1, brr, t + 2, arr.length - t - 1);
        brr[t + 1] = num;
        System.out.println(Arrays.toString(brr));
    }
}
